package csu.big_article.mapper;

import csu.big_article.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;

@Mapper
public interface UserMapper {

    @Select("select * from user where id = #{id} ")
    public User getUserById(Integer id);

    @Select("select * from user where username = #{username}")
    public User getUserByName(String username);

    @Insert("insert into user (username,password,create_time,update_time) VALUES (#{username},#{password},now(),now())")
    public void register(String username, String password);

    @Update("update user set nickname=#{nickname},email= #{email},update_time=#{updateTime} where id = #{id}")
    public void update(User user);

    @Update("update user set user_pic=#{avatarUrl},update_time=#{updateTime} where id=#{id}")
    public void updateAvatar(String avatarUrl, Integer id, LocalDateTime updateTime);

    @Update("update user set password=#{pwd},update_time=#{updateTime} where id=#{id}")
    public void updatePwd(String pwd, Integer id, LocalDateTime updateTime);
}
